<div class="row">
	<div class="col-sm-12">

	<form action="<?php echo DOMAIN_NURSERY?>/admin/add" method="post"  id='add_admin_form'>
	
	<table id="inputs-table" class="table table-striped table-bordered table-hover">
		<tr>
			<td width="100" align="right"><span class="red">*</span>用户名：</td>
			<td>
				<input type="text" name="username"  id="data-admin-username"
					   value="<?php echo set_value('username')?>" style="width: 30%" maxlength="20" >
				<label class="red" id="data-role-name-error"></label>
			</td>
		</tr>
		<tr>
			<td class="text-right"><span class="red">*</span>密码：</td>
			<td>
				<input type="password" name="pass"  id="data-admin-pass"
					   value="<?php echo set_value('pass')?>"  style="width: 30%" maxlength="20">
				<label class="red" id="data-role-pass-error"></label>
			</td>
		</tr>
		
		<tr>
			<td class="text-right" width="100" valign="top">管理员昵称：</td>
			<td  style="height: 50px;">
				<input type="text" name="nickname"  id="data-admin-nickname"
					   value="<?php echo set_value('nickname')?>" maxlength="40">
				<label class="red" id="data-role-nickname-error"><?php echo form_error('nickname')?></label>
			</td>
		</tr>
			
		<tr>
			<td class="text-right"><span class="red">*</span>选择角色：</td>
			<td>
				<select name='rid'>
					<?php foreach( $roles as $e ):?>
					<option value=<?php echo $e['id']?>><?php echo $e['name']?></option>
					<?php endforeach;?>
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
				<button class="btn btn-info btn-sm" type="button" id="add-admin-submit">提交</button>
			</td>
		</tr>
	</table>
</form>
</div>
</div>

<script type="text/javascript">

	//点击提交按钮时 进行验证 如果通过验证 那么提交表单
	$(document).on('click', '#add-admin-submit', function () {

		var name=$('#data-admin-username').val();

		var admin_pass=$('#data-admin-pass').val();

		//第一级验证
		if (name == false) {
			$('#data-role-name-error').html('用户名不能为空！');
			return false;
		}

		//第一级验证
		if (admin_pass == false) {
			$('#data-role-pass-error').html('密码不能为空！');
			return false;
		}else{


			var admin_pass=$('#data-admin-pass').val();
			var url='<?php echo DOMAIN_MAIN?>/api/npermissions/check_admin_pass';
			var params={
				admin_pass:admin_pass
			};

			$.get(url, params, function (data) {
				if(data.state=='success')
				{
					if(data.error_type==1){
						var new_dom='管理员密码须大于6位，请继续输入！';
					}else if(data.error_type==2){
						var new_dom='管理员密码须小于30位，请重新填写！';
					}

					$("#data-role-pass-error").html(new_dom);

					return false;
				}else{
					$("#data-role-pass-error").html('');
					$("#add_admin_form").submit();
				}

			},'json');

		}

	});

</script>
